package com.egao.api.controller.orderB;


import com.egao.common.core.annotation.OperLog;
import com.egao.common.core.damon.results.PageResult2;
import com.egao.common.core.web.BaseController;
import com.egao.common.core.web.JsonResult;
import com.egao.common.system.entity.User;
import com.egao.common.system.service.OperRecordService;
import com.egao.orderB.entity.Driver;
import com.egao.orderB.service.DriverService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

//import com.egao.orderB.entity.Bill;
//import com.egao.orderB.service.BillService;

/**
 * api登录相关接口
 * Created by wangfan on 2019-05-29 下午 3:43.
 * http://localhost/swagger-ui.html
 * https://francjc.com:4332/swagger-ui.html
 */
@RequestMapping("/api/driver")
@RestController
@Api(value = "司机管理",tags = {"司机管理"})
public class ApiDriveController extends BaseController {

    @Autowired
    private OperRecordService operRecordService;
    @Autowired
    private DriverService driverService;

    /**
     * 添加运费报价
     */
    @PreAuthorize("hasAuthority('orderB:driver:list')")
    @PostMapping("/list")
    @ApiOperation(value = "司机列表",notes = "" +
            "limit:每页显示几行 必填\n" +
            "page:第几页 必填\n" +
            "carTeam:车队\n" +
            "name:司机姓名\n" +
            "whiteCard:白卡号\n" +
            "state: 状态:未审核/已审核\n" +
            "carNo:车牌\n" +
            "phone:电话\n" +
            "返回的内容id:id\n" +
            "organizationId:组织id\n" +
            "carTeam:车队\n" +
            "phone:电话\n" +
            "urgentPhone 紧急联系人电话\n" +
            "name:姓名\n" +
            "idCard:身份证\n" +
            "idCard:身份证\n" +
            "carNo:车牌\n" +
            "whiteCardPic 白卡号图片\n" +
            "whiteCard:白卡号文字\n" +
            "whiteCardDateStart;//白卡号开始日期\n" +
            "whiteCardDate;//白卡号结束日期\n" +
            "vehicleLicense:行驶证图片\n" +
            "vehicleLicenseDateStart;//行驶证开始日期\n" +
            "vehicleLicenseDate;//行驶证结束日期\n" +
            "driveLicense:驾驶证图片\n" +
            "driveLicenseDateStart;//驾驶证开始日期\n" +
            "driveLicenseDate;//驾驶证结束日期\n" +
            "operationLicense:车辆营运证图片\n" +
            "operationLicenseDateStart;//车辆营运证开始日期\n" +
            "operationLicenseDate;//车辆营运证结束日期\n" +
            "insuranceLicense:保险图片\n" +
            "insuranceLicenseDateStart;//保险开始日期\n" +
            "insuranceLicenseDate;//保险结束日期\n" +
//            "qualificationCertificate:司机从业资格证图片\n" +
            "bankName:银行名称\n" +
            "bankNo:银行卡卡号\n" +
            "state:审核状态: 已审核,未审核,审核未通过\n" +
            "orderNum:排序\n" +
            "createTime:创建时间\n" +
            "",httpMethod = "POST")
    public JsonResult list(PageResult2<T> page, Driver driver, HttpServletRequest request)  throws Exception{
        return driverService.list(page, driver, getLoginUser());
    }

    /**
     * 添加运费报价
     */
    @PreAuthorize("hasAuthority('orderB:driver:list')")
    @PostMapping("/listAll")
    @ApiOperation(value = "司机列表",notes = "" +
            "",httpMethod = "POST")
    public JsonResult listAll(Driver driver, HttpServletRequest request)  throws Exception{
        return driverService.list(driver, getLoginUser());
    }

    /**
     * 添加运费报价
     */
    @PreAuthorize("hasAuthority('orderB:driver:list')")
    @PostMapping("/list2")
    @ApiOperation(value = "司机列表",notes = "" +
            "limit:每页显示几行 必填\n" +
            "page:第几页 必填\n" +
            "name:司机姓名 精确查找\n" +
            "whiteCard:白卡号\n" +
            "state: 状态:未审核/已审核\n" +
            "carNo:车牌\n" +
            "carTeam:车队名称 精确查找\n" +
            "\n" +
            "返回的内容id:id\n" +
            "organizationId:组织id\n" +
            "carTeamId:车队id\n" +
            "carTeam:车队名称\n" +
            "phone:电话\n" +
            "urgentPhone 紧急联系人电话\n" +
            "name:姓名\n" +
            "idCard:身份证\n" +
            "carNo:车牌\n" +
            "whiteCardPic 白卡号图片\n" +
            "whiteCard:白卡号文字\n" +
            "whiteCardDateStart;//白卡号开始日期\n" +
            "whiteCardDate;//白卡号结束日期\n" +
            "vehicleLicense:行驶证图片\n" +
            "vehicleLicenseDateStart;//行驶证开始日期\n" +
            "vehicleLicenseDate;//行驶证结束日期\n" +
            "driveLicense:驾驶证图片\n" +
            "driveLicenseDateStart;//驾驶证开始日期\n" +
            "driveLicenseDate;//驾驶证结束日期\n" +
            "operationLicense:车辆营运证图片\n" +
            "operationLicenseDateStart;//车辆营运证开始日期\n" +
            "operationLicenseDate;//车辆营运证结束日期\n" +
            "insuranceLicense:保险图片\n" +
            "insuranceLicenseDateStart;//保险开始日期\n" +
            "insuranceLicenseDate;//保险结束日期\n" +
//            "qualificationCertificate:司机从业资格证图片\n" +
            "bankName:银行名称\n" +
            "bankName:银行名称\n" +
            "bankNo:银行卡卡号\n" +
            "state:审核状态: 已审核,未审核,审核未通过\n" +
            "orderNum:排序\n" +
            "createTime:创建时间\n" +
            "",httpMethod = "POST")
    public JsonResult list2(PageResult2<T> page, Driver driver, HttpServletRequest request)  throws Exception{
        return driverService.list(page, driver, getLoginUser());
    }

    /**
     * 添加司机
     */
    @PreAuthorize("hasAuthority('orderB:driver:save')")
    @OperLog(value = "订单流程状态管理", desc = "平台手动添加司机", result = true)
    @PostMapping("/platsave")
    @ApiOperation(value = "平台手动添加司机",notes = "" +
            "所有的图片都保存到这个文件夹里面去/api/nt/file/registerDriver\n" +
            "username:帐号/手机号 必填\n" +
            "phone:电话 必填\n" +
            "urgentPhone 紧急联系人电话\n" +
            "name:姓名\n" +
            "idCardPic:身份证图片\n" +
            "idCard:身份证\n" +
            "carTeamId:车队id\n" +
            "carTeam:车队名称\n" +
            "carNo:车牌\n" +
            "whiteCardPic 白卡号图片\n" +
            "whiteCard:白卡号文字\n" +
            "whiteCardDateStart;//白卡号开始日期\n" +
            "whiteCardDate;//白卡号结束日期\n" +
            "vehicleLicense:行驶证图片\n" +
            "vehicleLicenseDateStart;//行驶证开始日期\n" +
            "vehicleLicenseDate;//行驶证结束日期\n" +
            "driveLicense:驾驶证图片\n" +
            "driveLicenseDateStart;//驾驶证开始日期\n" +
            "driveLicenseDate;//驾驶证结束日期\n" +
            "operationLicense:车辆营运证图片\n" +
            "operationLicenseDateStart;//车辆营运证开始日期\n" +
            "operationLicenseDate;//车辆营运证结束日期\n" +
            "insuranceLicense:保险图片\n" +
            "insuranceLicenseDateStart;//保险开始日期\n" +
            "insuranceLicenseDate;//保险结束日期\n" +
//            "qualificationCertificate:司机从业资格证图片\n" +
            "bankName:银行名称\n" +
            "bankNo:银行卡卡号\n" +
            "",httpMethod = "POST")
    public JsonResult platsave(Driver driver, User user, HttpServletRequest request) {
        try {
            return driverService.platsave(driver, user, getLoginUser());
        } catch (DuplicateKeyException e) {
            return JsonResult.error("帐号已使用");
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.error(e.getMessage());
        }
    }

    /**
     * 添加司机
     */
    @PreAuthorize("hasAuthority('orderB:driver:save')")
    @OperLog(value = "订单流程状态管理", desc = "excel导入司机", result = true)
    @PostMapping("/excelsave")
    @ApiOperation(value = "excel导入司机",notes = "excel导入司机" +
            "所有的图片都保存到这个文件夹里面去/api/nt/file/registerDriver\n" +
            "username:帐号/手机号必填\n" +
            "phone:电话必填\n" +
            "urgentPhone 紧急联系人电话\n" +
            "name:姓名\n" +
            "idCardPic:身份证图片\n" +
            "idCard:身份证\n" +
            "carTeamId:车队id\n" +
            "carTeam:车队名称\n" +
            "carNo:车牌\n" +
            "whiteCardPic 白卡号图片\n" +
            "whiteCard:白卡号文字\n" +
            "whiteCardDateStart;//白卡号开始日期\n" +
            "whiteCardDate;//白卡号结束日期\n" +
            "vehicleLicense:行驶证图片\n" +
            "vehicleLicenseDateStart;//行驶证开始日期\n" +
            "vehicleLicenseDate;//行驶证结束日期\n" +
            "driveLicense:驾驶证图片\n" +
            "driveLicenseDateStart;//驾驶证开始日期\n" +
            "driveLicenseDate;//驾驶证结束日期\n" +
            "operationLicense:车辆营运证图片\n" +
            "operationLicenseDateStart;//车辆营运证开始日期\n" +
            "operationLicenseDate;//车辆营运证结束日期\n" +
            "insuranceLicense:保险图片\n" +
            "insuranceLicenseDateStart;//保险开始日期\n" +
            "insuranceLicenseDate;//保险结束日期\n" +
//            "qualificationCertificate:司机从业资格证图片\n" +
            "bankName:银行名称\n" +
            "bankNo:银行卡卡号\n" +
            "[{\"username\":\"1112\",\"name\":\"1112\",\"idCard\":\"1112\",\"carTeamId\":\"185\",\"carTeam\":\"海元物流\",\"phone\":\"1112\",\"carNo\":\"1112\",\"whiteCard\":\"1112\",\"vehicleLicense\":\"1112\",\"driveLicense\":\"1112\",\"corporationLicensePic\":\"1112\",\"operationLicense\":\"1112\",\"qualificationCertificate\":\"1112\",\"bankName\":\"1112\",\"bankNo\":\"1112\"},{\"username\":\"1113\",\"name\":\"1113\",\"idCard\":\"1113\",\"carTeamId\":\"185\",\"carTeam\":\"海元物流\",\"phone\":\"1113\",\"carNo\":\"1113\",\"whiteCard\":\"1113\",\"vehicleLicense\":\"1113\",\"driveLicense\":\"1113\",\"corporationLicensePic\":\"1113\",\"operationLicense\":\"1113\",\"qualificationCertificate\":\"1113\",\"bankName\":\"1113\",\"bankNo\":\"1113\"}]\n" +
            "",httpMethod = "POST")
    public JsonResult excelsave(@RequestBody List<Driver> driverList, HttpServletRequest request) throws Exception {
        return driverService.excelsave(driverList, getLoginUser());
    }

    /**
     * 司机修改
     */
    @PreAuthorize("hasAuthority('orderB:driver:update')")
    @OperLog(value = "订单流程状态管理", desc = "司机修改", result = true)
    @PostMapping("/update")
    @ApiOperation(value = "司机修改",notes = "" +
            "所有的图片都保存到这个文件夹里面去/api/nt/file/registerDriver\n" +
            "id 司机的id 必填\n" +
            "carTeamId:车队id\n" +
            "carTeam:车队\n" +
            "name:司机姓名\n" +
            "phone:电话\n" +
            "urgentPhone 紧急联系人电话\n" +
            "carNo:车牌\n" +
            "idCardPic:身份证图片\n" +
            "idCard:身份证\n" +
            "whiteCardPic 白卡号图片\n" +
            "whiteCard:白卡号文字\n" +
            "whiteCardDateStart;//白卡号开始日期\n" +
            "whiteCardDate;//白卡号结束日期\n" +
            "vehicleLicense:行驶证图片\n" +
            "vehicleLicenseDateStart;//行驶证开始日期\n" +
            "vehicleLicenseDate;//行驶证结束日期\n" +
            "driveLicense:驾驶证图片\n" +
            "driveLicenseDateStart;//驾驶证开始日期\n" +
            "driveLicenseDate;//驾驶证结束日期\n" +
            "operationLicense:车辆营运证图片\n" +
            "operationLicenseDateStart;//车辆营运证开始日期\n" +
            "operationLicenseDate;//车辆营运证结束日期\n" +
            "insuranceLicense:保险图片\n" +
            "insuranceLicenseDateStart;//保险开始日期\n" +
            "insuranceLicenseDate;//保险结束日期\n" +
//            "qualificationCertificate:司机从业资格证图片\n" +
            "bankName:银行名称\n" +
            "bankNo:银行卡卡号\n",httpMethod = "POST")
    public JsonResult update(Driver driver, HttpServletRequest request) {
        return driverService.update(driver, getLoginUser());
    }

    /**
     * 司机对司机信息的修改
     */
    /*@PreAuthorize("hasAuthority('orderB:driver:update')")
    @OperLog(value = "订单流程状态管理", desc = "司机对司机信息修改", result = true)
    @PostMapping("/driverUpdate")
    @ApiOperation(value = "司机对司机信息修改",notes = "" +
            "所有的图片都保存到这个文件夹里面去/api/nt/file/registerDriver\n" +
            "id 司机的id 必填\n" +
            "name:司机姓名\n" +
            "phone:电话\n" +
            "carNo:车牌\n" +
            "idCardPic:身份证图片\n" +
            "idCard:身份证\n" +
            "whiteCardPic 白卡号图片\n" +
            "whiteCard:白卡号文字\n" +
            "whiteCardDateStart;//白卡号开始日期\n" +
            "whiteCardDate;//白卡号结束日期\n" +
            "vehicleLicense:行驶证图片\n" +
            "vehicleLicenseDateStart;//行驶证开始日期\n" +
            "vehicleLicenseDate;//行驶证结束日期\n" +
            "driveLicense:驾驶证图片\n" +
            "driveLicenseDateStart;//驾驶证开始日期\n" +
            "driveLicenseDate;//驾驶证结束日期\n" +
            "operationLicense:车辆营运证图片\n" +
            "operationLicenseDateStart;//车辆营运证开始日期\n" +
            "operationLicenseDate;//车辆营运证结束日期\n" +
            "insuranceLicense:保险图片\n" +
            "insuranceLicenseDateStart;//保险开始日期\n" +
            "insuranceLicenseDate;//保险结束日期\n" +
//            "qualificationCertificate:司机从业资格证图片\n" +
            "bankName:银行名称\n" +
            "bankNo:银行卡卡号\n" +
            "",httpMethod = "POST")
    public JsonResult driverUpdate(Driver driver, HttpServletRequest request) {
        return driverService.driverUpdate(driver, getLoginUser());
    }*/

    @PreAuthorize("hasAuthority('orderB:driver:remove')")
    @OperLog(value = "订单流程状态管理", desc = "司机审核通过", result = true)
    @PostMapping("/examineSuccess")
    @ApiOperation(value = "司机审核通过",notes = "id driver表的id",httpMethod = "POST")
    public JsonResult examineSuccess(Driver driver, HttpServletRequest request) {
        return driverService.examine(driver, getLoginUser());
    }

    /**
     * 司机修改
     */
    @PreAuthorize("hasAuthority('orderB:driver:remove')")
    @OperLog(value = "司机删除", desc = "删除")
    @PostMapping("/remove")
    @ApiOperation(value = "司机删除",notes = "" +
            "id 司机的id 必填\n" +
            "",httpMethod = "POST")
    public JsonResult remove(Driver driver, HttpServletRequest request) {
        return driverService.remove(driver, getLoginUser());
    }

    /**
     * 司机修改
     */
    @PreAuthorize("hasAuthority('orderB:driver:remove')")
    @OperLog(value = "审核司机驳回", desc = "删除")
    @PostMapping("/removeReal")
    @ApiOperation(value = "审核司机驳回",notes = "" +
            "id 司机的id 必填\n" +
            "name 司机姓名 必填\n" +
            "phone 电话 必填\n" +
            "",httpMethod = "POST")
    public JsonResult removeReal(Driver driver, HttpServletRequest request) {
        return driverService.removeReal(driver);
    }

}
